package cn.edu.nuc.ssm.dao;

import cn.edu.nuc.ssm.dto.BbsReplyAndUsername;
import cn.edu.nuc.ssm.dto.BbsReplyFirstAndUsername;
import cn.edu.nuc.ssm.dto.SecondBbsReblyAndRAndToUsername;
import cn.edu.nuc.ssm.entity.BbsReply;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BbsReplyMapper {
    @Delete({
        "delete from bbs_reply",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into bbs_reply ( sid, ",
        "uid,reply_uid, tid, content, ",
        "reply_time, click_count,level,pid)",
        "values ( #{sid,jdbcType=INTEGER}, ",
        "#{uid,jdbcType=INTEGER}, #{reply_uid,jdbcType=INTEGER},#{tid,jdbcType=INTEGER}, #{content,jdbcType=VARCHAR}, ",
        "#{replyTime,jdbcType=CHAR}, #{clickCount,jdbcType=INTEGER},#{level,jdbcType=INTEGER},#{pid,jdbcType=INTEGER})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(BbsReply record);

    int insertSelective(BbsReply record);

    @Select({
        "select",
        "id, sid, uid,reply_uid, tid, content, reply_time, click_count,level,pid",
        "from bbs_reply",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("cn.edu.nuc.ssm.dao.BbsReplyMapper.BaseResultMap")
    BbsReply selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(BbsReply record);

    @Update({
        "update bbs_reply",
        "set sid = #{sid,jdbcType=INTEGER},",
          "uid = #{uid,jdbcType=INTEGER},",
          "tid = #{tid,jdbcType=INTEGER},",
            "reply_uid = #{reply_uid,jdbcType=INTEGER},",
          "content = #{content,jdbcType=VARCHAR},",
          "reply_time = #{replyTime,jdbcType=CHAR},",
          "click_count = #{clickCount,jdbcType=INTEGER},",
            "level = #{level,jdbcType=INTEGER},",
            "pid = #{pid,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(BbsReply record);


//    @Select({
//            "select",
//            "id, sid, uid,reply_uid, tid, content, reply_time, click_count,level,pid,u.username",
//            "from bbs_reply r,user u left join on r.uid=u.id where uid=#{uid} AND sid=#{sid} AND tid=#{tid} AND LEVEL=#{level} ",
//            "limit #{start},#{offset}"
//    })
    List<BbsReplyFirstAndUsername> findPageList(@Param("uid") int uid,@Param("sid") int sid,@Param("tid") int tid,@Param("level") int level,@Param("start") int start, @Param("offset") int offset);

    List<SecondBbsReblyAndRAndToUsername> findbytidAnd2level(@Param("tid")Integer tid);



    int countReply(@Param("uid") int uid,@Param("sid") int sid,@Param("tid") int tid,@Param("level") int level);

    BbsReplyAndUsername findbyIdandlevel(@Param("id")Integer id, @Param("level")Integer level);


    int deletebySid(@Param("sid")Integer sid);

	List<BbsReply> findbySid(@Param("sid")Integer sid);

    int deletebyTid(@Param("tid")Integer tid);

	List<BbsReply> findbyTid(@Param("tid")Integer tid);

    int deletebyidorpid(@Param("id")Integer id,@Param("pid")Integer pid);


    List<BbsReply> find();




}